#ifndef _MCMCPARTICLESURFACE_H
#define _MCMCPARTICLESURFACE_H

#include "mcmcParticle.h"

class MCMC_ControlPoints
{
public:
	// construction & destruction
	MCMC_ControlPoints();
	~MCMC_ControlPoints();
	
	// operators
	MCMC_ControlPoints& operator=(const MCMC_ControlPoints& a);

	// operations
	virtual void		Initialize(mcmcMatrix<int> &mx_cluster, const int label, mcmcMatrix<int> *pmx_taken,
								   Raster<float> &image, irmm_Rect *pbound=NULL);
	virtual void		Initialize(LinkList<PMCMC_PixelSet> &list_domain, mcmcMatrix<int> *pmx_taken, Raster<float> &image);
	virtual void		Initialize(mcmcMatrix<int> &mx_cluster, const int label, mcmcMatrix<int> *pmx_taken,
									Raster<float> &image, mcmcMatrix<int> &mx_medial_row, mcmcMatrix<int> &mx_medial_col,
								   mcmcMatrix<int> &mx_medial_dist, irmm_Rect *pbound=NULL);
	
	virtual void		Estimate(void);
	virtual double		SurfaceValue(const int row, const int col);
	virtual int		TotalCodingBits(void);

protected:
	virtual void		ComputeUW(const int row, const int col);

public:
	mcmcMatrix<double>		mx_P;

protected:
	mcmcMatrix<double>		*pmx_A;
	mcmcMatrix<double>		mx_B;
	int				num_pixels;
	mcmcMatrix<double>		mx_par;
	bool				belongated;
	mcmcMatrix<int>		*pmx_medial_row,*pmx_medial_col;
	mcmcMatrix<int>		*pmx_medial_dist;
	mcmcVector<double>		vc_a;
	mcmcVector<double>		vc_c;

private:
	int					nrow;
	int					ncol;
	mcmcVector<double>		vc_u,vc_w;
};

// surface model for intensity images
class MCMC_Particle_Surface : public MCMC_Particle
{
public:
	// construction & destruction
	MCMC_Particle_Surface();
	~MCMC_Particle_Surface();
	void Free(void){;};

	// operations
	virtual void			Set(MCMC_FilterResp &respFilters, mcmcMatrix<int> &clst, char *pfile_name=NULL);
	virtual double			DistanceToPar(const int row_j, const int col_i, const int ipar){return 0.0;};
	virtual	double			CombinedDist(const mcmcVector<double> &vc_dist){return 0.0;};
	virtual void			CreateSoftClusteringMap(void){;};

	virtual mcmcVector<double>	GetMean(const int iparticle){mcmcVector<double> a; return a;};
	virtual int				ClosestParticle(mcmcVector<double> &mx_mean){return 0;};
	virtual int				CloserParticle(const mcmcVector<double> &mx_mean1, const mcmcVector<double> &mx_mean2, const int ipar){return 0;};
	virtual void			Diffuse(mcmcVector<double> &mx_mean, const int ipar){;};
	virtual	void			FitSurface(void);
	virtual double			DistanceBtwnParticles(const int ipar1, const int ipar2);
	virtual double			DistanceToAParticle(double intensity, const int ipar, const int j, const int i);
	virtual void			EM(void);
	virtual void			CreateSalincyMap(void);

protected:
	mcmcVector<double>			vc_weights;
	double					dist_to_merge;
	MCMC_ControlPoints		*p_surface_model;
	Raster<float>			*p_synthesized;

protected:
	bool					bprint_histograms;
};


// surface model for color images
class MCMC_Particle_SurfaceColor: public MCMC_Particle
{
public:
	// construction & destruction
	MCMC_Particle_SurfaceColor();
	~MCMC_Particle_SurfaceColor();
	void Free(void){;};

	// operations
	virtual void			Set(MCMC_FilterResp &respFilters, mcmcMatrix<int> &clst, char *pfile_name=NULL);
	virtual double			DistanceToPar(const int row_j, const int col_i, const int ipar){return 0.0;};
	virtual	double			CombinedDist(const mcmcVector<double> &vc_dist){return 0.0;};
	virtual void			CreateSoftClusteringMap(void){;};

	virtual mcmcVector<double>	GetMean(const int iparticle){mcmcVector<double> a; return a;};
	virtual int				ClosestParticle(mcmcVector<double> &mx_mean){return 0;};
	virtual int				CloserParticle(const mcmcVector<double> &mx_mean1, const mcmcVector<double> &mx_mean2, const int ipar){return 0;};
	virtual void			Diffuse(mcmcVector<double> &mx_mean, const int ipar){;};
	virtual	void			FitSurface(void);
	virtual double			DistanceBtwnParticles(const int ipar1, const int ipar2);
	virtual double			DistanceToAParticle(const double pixel_l, const double pixel_u, const double pixel_v,
												const int ipar, const int j, const int i);
	virtual void			EM(void);
	virtual void			CreateSalincyMap(void);

protected:
	mcmcVector<double>			vc_weights;
	double					dist_to_merge;
	MCMC_ControlPoints		*p_surface_model[3];
	Raster<float>			*p_synthesized[3];

protected:
	bool					bprint_histograms;
};





#endif